<template>
	<div class="add-scrap-device">
		<div>
			<label>{{$t('route.Maintenance_Management')}}</label>
			<div></div>
			<button><img /><label>{{$t('route.Add_scrap_equipment')}}</label></button>
		</div>
		<div>
			<div class="div-1">
				<label class="title">{{$t('route.Head_Model')}}:</label>
				<label class="content">{{form.noseCode}}</label>
				<label class="title">{{$t('route.Workshop')}}:</label>
				<label class="content">{{form.workshop}}</label>
			</div>

			<div class="div-1">
				<label class="title">{{$t('route.Scrapper')}}:</label>
				<el-input class="content" v-model="form.nickname" />
				<label class="title">{{$t('route.contact_number')}}:</label>
				<el-input oninput="value=value.replace(/[^0-9.]/g,'')" class="content" v-model="form.mobile" />
			</div>

			<div class="div-1">
				<label class="title">{{$t('route.Processing_method')}}:</label>
				<el-select class="content" v-model="form.handle" :placeholder="$t('route.Please_Select')">
					<el-option :label="$t('route.Factory_recycling')" :value="$t('route.Factory_recycling')" />
					<el-option :label="$t('route.Scrap_sales')" :value="$t('route.Scrap_sales')" />
				</el-select>
				<label class="title">{{$t('route.Reason_for_scrapping')}}:</label>
				<el-input class="content" type="textarea" v-model="form.reason" />
			</div>

			<div class="div-1">
				<label class="title"></label>
				<el-button @click='saveClick'>{{$t('route.preservation')}}</el-button>
			</div>

		</div>


	</div>
</template>

<script>
	import http from "../../js/http/http.js";
	import api from "../../js/http/api.js";
	import CommonUtils from "../../js/common/common-utils.js";
	import i18n from '../../i18n/index';
	export default {
		data() {
			return {
				deviceId: null,
				repairId: null,
				form: {
					noseCode: null,
					workshop: null,
					nickname: null,
					mobile: null,
					handle: i18n.global.t('route.Factory_recycling'),
					reason: null,
				},
			};
		},
		methods: {
			getDeviceDetail() {
				http.post(api.GET_DEVICE_DETAIL, {
					deviceId: this.deviceId,
				}, data => {
					this.form.noseCode = data.data.noseCode;
					this.form.workshop = data.data.workshop;
				})
			},
			saveClick() {
				if (CommonUtils.isEmpty(this.form.nickname)) {
					this.$message.error(i18n.global.t('route.The_scrap_person_cannot_be_blank'));
					return;
				}
				if (CommonUtils.isEmpty(this.form.mobile)) {
					this.$message.error(i18n.global.t('route.Contact_number_cannot_be_empty'));
					return;
				}
				if (CommonUtils.isEmpty(this.form.handle)) {
					this.$message.error(i18n.global.t('route.Processing_method_cannot_be_empty'));
					return;
				}
				if (CommonUtils.isEmpty(this.form.reason)) {
					this.$message.error(i18n.global.t('route.Scrap_reason_cannot_be_empty'));
					return;
				}

				this.addScrapRecord();

			},
			addScrapRecord() {
				http.post(api.ADD_SCRAP_RECORD, {
					adminId: this.$store.state.user.id,
					deviceId: this.deviceId,
					repairId: this.repairId,
					reason: this.form.reason,
					nickname: this.form.nickname,
					mobile: this.form.mobile,
					handle: this.form.handle,
				}, data => {
					this.$message.success(18n.global.t('route.Saved_successfully'));
					this.$router.push('/scrap-device');
				})

			}


		},
		created() {
			this.deviceId = CommonUtils.getParam(this, 'deviceId', 'setDeviceId');
			this.repairId = CommonUtils.getParam(this, 'repairId', 'setRepairId');
			this.getDeviceDetail();
		}

	};
</script>
<style lang="scss" scoped>
	.add-scrap-device {
		color: #444444;
		font-size: 18px;
		padding-right: 20px;
		height: calc(100vh - 100px);
		// overflow: scroll;
		scrollbar-width: none;
		/* firefox */
		-ms-overflow-style: none;
		/* IE 10+ */
		overflow-x: hidden;
		overflow-y: auto;

		>div {
			display: flex;
			flex-direction: row;
			align-items: center;
			margin-top: 20px;
			background-color: #ffffff;
			padding: 20px;
			border-radius: 5px;
		}

		>div:nth-of-type(1) {

			>label:nth-of-type(1) {
				font-weight: 600;
			}

			>div:nth-of-type(1) {
				width: 1px;
				background-color: #cccccc;
				height: 15px;
				margin: 0px 20px;
			}

			>button:nth-of-type(1) {
				background-image: url(../../assets/img/customer-1.png);
				background-repeat: no-repeat;
				background-size: 100% 100%;
				padding: 5px 10px;
				border: 0px;
				display: flex;
				color: #ffffff;
				flex-direction: row;
				align-items: center;
				font-weight: 800;

				>img {
					margin-right: 7px;
					width: 15px;
					height: 15px;
					content: url(../../assets/img/customer-2.png);
				}

			}
		}

		>div:nth-of-type(2) {
			flex-direction: column;
			align-items: flex-start;


			.div-1 {
				display: flex;
				flex-direction: row;
				margin-top: 10px;
				align-items: center;

				.title {
					width: 200px;
					text-align: right;
				}

				.content {
					margin-left: 20px;
					width: 250px;
				}


				>button {
					margin-left: 20px;
					width: 250px;
				}
			}
		}

	}
</style>
